package com.yyk.yiliao.ui.gongyong.activity;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.listener.ToolbarListenter;
import com.yyk.yiliao.ui.activity.detail.activity.PayPleaceOrder_Activity;
import com.yyk.yiliao.ui.activity.dingdan.activity.CommodityOrde_Activity;
import com.yyk.yiliao.ui.mine.activity.Registration_Activity;

import butterknife.BindView;
import butterknife.OnClick;

public class PaySuccess_Activity extends BaseActivity {


    @BindView(R.id.tv_black) //查看订单
            TextView tvBlack;
    @BindView(R.id.tv_money) //支付金额
            TextView tvMoney;
    @BindView(R.id.tv_paymonth)//支付方式
            TextView tvPaymonth;

    private int flag = 1; //1. 商品订单，2. 预约挂号，3.重新下单


    @Override
    public int getLayoutId() {
        return R.layout.activity_pay_success;
    }

    @Override
    public void initView() {
        setTitle("订单支付成功");
        setMainTitleRightText("完成", new ToolbarListenter() {
            @Override
            public void onClickListenter() {
//                if (ShopCart_Activity.intanse != null) {
//                    ShopCart_Activity.intanse.finish();
//                }
                if (PayPleaceOrder_Activity.intanse != null) {
                    PayPleaceOrder_Activity.intanse.finish();
                }
                finish();
            }
        });

    }

    @Override
    public void initData() {
        if (getBundle() != null) {
            String money = getBundle().getString("money");
            String paymonth = getBundle().getString("paymonth");
            flag = Integer.parseInt(getBundle().getString("flag"));
            tvPaymonth.setText("支付方式：" + paymonth);
            tvMoney.setText("支付金额：￥" + money);
        }
    }


    @OnClick({R.id.tv_black})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_black:
                if (flag == 1) {
                    Intent intent = new Intent();
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startAct(intent, CommodityOrde_Activity.class, null);
                } else if (flag == 2) {
                    Intent intent = new Intent();
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startAct(intent, Registration_Activity.class, null);
                }
                break;
        }
    }

    //禁止使用返回键返回到上一页,但是可以直接退出程序**
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            moveTaskToBack(true);
            return true;//不执行父类点击事件
        }
        return super.onKeyDown(keyCode, event);//继续执行父类其他点击事件
    }



}

